package com.logicalthinking.socialmall.conf;

import com.github.chenlijia1111.commonModule.service.IdGeneratorServiceI;
import com.github.chenlijia1111.commonModule.service.impl.*;
import com.github.chenlijia1111.utils.core.ParameterCheckProxy;
import com.github.chenlijia1111.utils.database.mybatis.PagePlugin;
import com.github.chenlijia1111.utils.oauth.jwt.JWTCheckUtil;
import com.logicalthinking.socialmall.common.pojo.Constants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenlijia
 * @version 1.0
 * @since 2019/8/8 0008 下午 7:50
 **/
@Configuration
public class BeanConfig {

    /**
     * 注入分页插件
     *
     * @return
     */
    @Bean
    public PagePlugin pageHelper() {
        PagePlugin pagePlugin = new PagePlugin();
        //设置自动分页,只有参数有page,limit就自己分页
        pagePlugin.setAutoPage(true);
        return pagePlugin;
    }

    /**
     * aop 参数校验
     *
     * @return
     */
    @Bean
    public ParameterCheckProxy parameterCheckProxy() {
        return new ParameterCheckProxy();
    }


    /**
     * admin jwt校验工具
     *
     * @return
     */
    @Bean("adminJWTCheckUtil")
    public JWTCheckUtil adminJWTCheckUtil() {
        JWTCheckUtil jwtCheckUtil = new JWTCheckUtil();
        //过期时间
        jwtCheckUtil.setExpireSeconds(Constants.ADMIN_LOGIN_LIMIT_TIME_SECONDS);
        //刷新时间 15分钟刷新一次
        jwtCheckUtil.setRefreshSeconds(Constants.ADMIN_LOGIN_LIMIT_TIME_SECONDS / 2);
        return jwtCheckUtil;
    }

    /**
     * 产品id生成器
     * @return
     */
    @Bean("productIdGeneratorService")
    public IdGeneratorServiceI productIdGeneratorService(){
        return new ProductIdGeneratorServiceImpl();
    }

    /**
     * 订单id生成器
     * @return
     */
    @Bean("ShoppingOrderNoGeneratorService")
    public IdGeneratorServiceI ShoppingOrderNoGeneratorService(){
        return new ShoppingIdGeneratorServiceImpl();
    }

    /**
     * 组订单编号生成器
     * @return
     */
    @Bean("groupIdGeneratorService")
    public IdGeneratorServiceI groupIdGeneratorService(){
        return new GroupIdGeneratorServiceImpl();
    }

    /**
     * 发货单编号生成器
     * @return
     */
    @Bean("sendOrderNoGeneratorService")
    public IdGeneratorServiceI sendOrderNoGeneratorService(){
        return new SendIdGeneratorServiceImpl();
    }

    /**
     * 收货单编号生成器
     * @return
     */
    @Bean("receiveOrderNoGeneratorService")
    public IdGeneratorServiceI receiveOrderNoGeneratorService(){
        return new ReceiveIdGeneratorServiceImpl();
    }

    /**
     * 退货单编号生成器
     * @return
     */
    @Bean("returnOrderNoGeneratorService")
    public IdGeneratorServiceI returnOrderNoGeneratorService(){
        return new ReturnIdGeneratorServiceImpl();
    }

    /**
     * 商家组订单生成器
     * @return
     */
    @Bean("shopGroupIdGeneratorService")
    public IdGeneratorServiceI shopGroupIdGeneratorService(){
        return new ShopGroupIdGeneratorServiceImpl();
    }

}
